import {Context, Next} from 'koa'
import {IUser} from '@/types/user.types'
import jwt from 'jsonwebtoken'
import {PRIVATE_KEY} from '@/app/config'

class AuthController {
  public login(ctx: Context, next: Next) {
    const { id, username } = ctx.user
    const token = jwt.sign({id, username}, PRIVATE_KEY, {
      expiresIn: 60 * 60 * 24,
      algorithm: 'RS256'
    })
    ctx.body = {
      code: 200,
      data: {id, username, token }
    }
  }

  public success(ctx: Context, next: Next) {
    ctx.body = '授权成功'
  }
}

export default new AuthController()